package com.wsb.boot.direct;

import com.rabbitmq.client.*;
import com.wsb.boot.utils.ConnectionUtil;

import java.io.IOException;

/**
 * @author wang shaobo
 * @date 2020/7/20  16:33
 */
public class Rec2 {

    private final static String QUEUE_NAME = "direct_exchange_queue_sms";//短信队列

    private final static String EXCHANGE_NAME = "test_direct_exchange";

    public static void main(String[] args) throws Exception{

        //获取连接
        Connection connection = ConnectionUtil.getConnection();
        //获取通道
        Channel channel = connection.createChannel();
        //声明队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        //绑定队列到交换机，同时指定routing key可以指定多个
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"email");

        //自定义消费队列
        DefaultConsumer consummer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                                       byte[] body) throws IOException {
                String msg = new String(body);
                System.out.println(" [邮件服务] received : " + msg + "!");

            }
        };

        channel.basicConsume(QUEUE_NAME,true,consummer);


    }
}
